 package util;
 
 import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;




 
 
 public final class StringUtil
 {
   private static final char[] charArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
   
 
 
 
   private static final char[] digitArray = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
   
   public static String randomDigit(int length) {
     char[] c = new char[length];
     Random random = new Random();
     for (int i = 0; i < length; i++)
       c[i] = digitArray[random.nextInt(digitArray.length)];
     return new String(c);
   }
   
   public static String randomString(int length) {
     char[] c = new char[length];
     Random random = new Random();
     for (int i = 0; i < length; i++)
       c[i] = charArray[random.nextInt(charArray.length)];
     return new String(c);
   }
   
 
 
   public static boolean isNullValue(String value)
   {
     return (value == null) || (value.trim().equals(""));
   }
   
 
 
 
 
 
 
 
 
 
 
   public static final String leftAppendStr(String input, int num, char chr)
   {
     int size = num - input.length();
     char[] c = new char[size];
     for (int i = 0; i < size; i++) {
       c[i] = chr;
     }
     return String.valueOf(c).concat(input);
   }
   
 
 
 
 
 
 
   public static final String leftAppendStr(String input, int num)
   {
     return leftAppendStr(input, num, '0');
   }
   
 
 
 
 
 
 
   public static String filterUnNumber(String str)
   {
     if (isNullValue(str)) {
       return "";
     }
     String regEx = "[^0-9]";
     Pattern p = Pattern.compile(regEx);
     Matcher m = p.matcher(str);
     
     return m.replaceAll("").trim();
   }
   
 
 
 
   public static boolean isDigit(String str)
   {
     String regEx = "(\\d+?)";
     Pattern p = Pattern.compile(regEx);
     Matcher m = p.matcher(str);
     return m.matches();
   }
   
 
 
 
 
   public static boolean isMobileNumber(String number)
   {
     if (isNullValue(number))
       return false;
     if (number.length() > 11)
       number = number.substring(number.length() - 11);
     Pattern p = Pattern.compile("^((13[0-9])|(14[0-9])|(15[0-9])|(18[0-9]))\\d{8}$");
     Matcher m = p.matcher(number);
     return m.matches();
   }
   
 
 
 
 
 
 
 
   public static String findFromString(String str, String regEx, String groupIndex)
   {
     return findFromString(str, regEx, groupIndex, false);
   }
   
 
 
 
 
 
 
 
   public static String findIgnoreCaseFromString(String str, String regEx)
   {
     return findFromString(str, regEx, "1", true);
   }
   
 
 
 
 
 
 
 
   public static String findIgnoreCaseFromString(String str, String regEx, String groupIndex)
   {
     return findFromString(str, regEx, groupIndex, true);
   }
   
   public static boolean isNumeric(String str) {
     return StringUtils.isNumeric(str);
   }
   
 
 
 
 
 
 
   public static String findFromString(String str, String regEx, String groupIndex, boolean ignoreCase)
   {
     if (isNullValue(str))
       return null;
     if (isNullValue(regEx))
       return null;
     Pattern p = null;
     if (ignoreCase) {
       p = Pattern.compile(regEx, 2);
     } else
       p = Pattern.compile(regEx);
     Matcher m = p.matcher(str);
     m = p.matcher(str);
     if (m.find()) {
       return m.group(Integer.parseInt(groupIndex));
     }
     return null;
   }
   
 
 
 
 
   public static final String getParameterValue(String argsList, String key)
   {
     if (isNullValue(argsList))
       return "";
     if (isNullValue(key)) {
       return "";
     }
     
 
 
     String reg = String.format("%s=(.*?)", new Object[] { key });
     String value = findFromString(argsList, reg.concat("&"), "1");
     if (value != null)
       return value;
     value = findFromString(argsList, "&".concat(reg).concat("&"), "1");
     if (value != null)
       return value;
     value = findFromString(argsList, "&".concat(reg).concat("$"), "1");
     return value == null ? "" : value;
   }
   
   public static final String escapeXml(String str)
   {
     if (isNullValue(str))
       return "";
     str = str.replaceAll("&", "&amp;");
     str = str.replaceAll("<", "&lt;");
     str = str.replaceAll(">", "&gt;");
     str = str.replaceAll("'", "&apos;");
     str = str.replaceAll("\"", "&quot;");
     return str;
   }
   
   public static final String unescapeXml(String str) {
     if (isNullValue(str))
       return "";
     str = str.replaceAll("&amp;", "&");
     str = str.replaceAll("&lt;", "<");
     str = str.replaceAll("&gt;", ">");
     str = str.replaceAll("&apos;", "'");
     str = str.replaceAll("&quot;", "\"");
     return str;
   }
   
   public static final boolean isValidMobileNumber(String number) {
     if (isNullValue(number))
       return false;
     if ((number.endsWith("00000000")) || (number.endsWith("13800138000")))
       return false;
     return isMobileNumber(number);
   }
   
 
 
 
 
   public static final String filterNullValue(String str)
   {
     return str == null ? "" : str.trim();
   }
   
 
 
 
 
   public static final String urlEncode(String url)
   {
     if (isNullValue(url)) {
       return "";
     }
     try
     {
       return URLEncoder.encode(url, "UTF-8");
     } catch (UnsupportedEncodingException e) {
       e.printStackTrace(); }
     return "";
   }
   /*
   public static void main(String[] args)
   {
     String params = "amt=1.00&app_id=5&cm=M2040066&display=4&order_no=20150115084600999&product_id=1410001&pType=1&body=000RES";
     String[] array = params.split("&");
     Arrays.sort(array);
     String[] arrayOfString1; int j = (arrayOfString1 = array).length; for (int i = 0; i < j; i++) { String str = arrayOfString1[i];
       System.out.println(str);
     }
     
   }
   */
   
   
   
 }


/* Location:              /home/cp/server/java/AndroidSdkServer.jar!/com/eyumob/common/util/StringUtil.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */